package com.qfedu.controller;

import com.qfedu.constants.Status;
import com.qfedu.model.Branch;
import com.qfedu.model.Contractor;
import com.qfedu.model.Project;
import com.qfedu.model.Stage;
import com.qfedu.page.PageResult;
import com.qfedu.page.QueryPageBean;
import com.qfedu.page.Result;
import com.qfedu.service.IBranchService;
import com.qfedu.service.IStageService;
import com.qfedu.vo.ConProVO;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 概述:
 *
 * @Author: Tbh
 * @Date: 2022/6/30 20:33
 */

@RestController
@RequestMapping("branch")
public class BranchController {

    @Autowired
    private IBranchService branchService;

    /**
     * @Author Tbh.
     * @Description: 查询所有任务计划
     * @Date 2022/7/1 20:48
     * @Param No parameters
     * @return 任务计划集合
     */
    @GetMapping("findAll")
    public List<Branch> findAll() {
        return branchService.findAll();
    }

    /**
     * @Author Tbh.
     * @Description: 开发商部门分页查询
     * @Date 2022/7/1 15:46
     * @Param QueryPageBean
     * @return PageResult
     */
    @PostMapping("all")
    public PageResult all(@RequestBody QueryPageBean queryPage) {
        PageResult page = branchService.findPage(queryPage);
        return page;
    }

    /**
     * @Author Tbh.
     * @Description: 新增开发商部门
     * @Date 2022/7/1 15:47
     * @Param Branch
     * @return Result
     */
    @PostMapping("add")
    public Result addStage(@RequestBody Branch branch) {
        int row = branchService.addBranch(branch);
        if (row > 0) {
            //枚举类名.对象名.get方法 获取到对应的属性值
            //Status.SUCCESS.name();  获取到枚举对象名  SUCCESS
            return Result.success();
        } else {
            return Result.fail();
        }
    }

    /**
     * @Author Tbh.
     * @Description: 数据回显
     * @Date 2022/7/1 15:45
     * @Param bid
     * @return Result
     */
    @GetMapping("findByBid")
    public Result findByBid(@RequestParam("bid") String bid) {
        Branch branch = branchService.findByBid(bid);
        Result result = new Result();
        result.setMessage(Status.FAIL.getMessage());
        if (ObjectUtils.isNotEmpty(branch)) {
            result.setFlag(true);
            result.setData(branch);
            result.setMessage(Status.SUCCESS.getMessage());
        }
        return result;
    }

    /**
     * @Author Tbh.
     * @Description: 修改开发商部门
     * @Date 2022/7/1 16:48
     * @Param Branch
     * @return Result
     */
    @PostMapping("edit")
    public Result edit(@RequestBody Branch branch) {
        int row = branchService.edit(branch);
        if (row > 0) {
            return Result.success();
        }
        return Result.fail();
    }

    /**
     * @Author Tbh.
     * @Description: 逻辑删除
     * @Date 2022/7/1 16:48
     * @Param
     * @return Result
     */
    @GetMapping("delete")
    public Result delete(@RequestParam("bid") String bid) {
        int row = branchService.deleteByBid(bid);
        if (row > 0) {
            return Result.success();
        } else {
            return Result.fail();
        }
    }
}
